package com.swh.converter;

import org.apache.commons.beanutils.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author: swh
 * @Description:
 * @Date: 2020/11/25 18:47
 * @Version: 1.0
 */
public class DateConverter implements Converter {
    @Override
    public <T> T convert(Class<T> aClass, Object o) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

        try {
            Date dateTime = format.parse(o.toString());
            return (T) dateTime;
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return null;
    }
}
